package com.sinux.sshUser.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sinux.sshUser.entity.Resources;
import com.sinux.sshUser.entity.Role;
import com.sinux.sshUser.service.ResourcesServiceI;

/**
 * @author WangGan
 * @version 2017年5月26日 上午9:18:44 
 * 
 */
@Controller
public class ResourcesController {
	
	@Autowired
	private ResourcesServiceI resService;
	
	/***分页资源列表***/
	@ResponseBody
	@RequestMapping("/restab")
	public Map<String ,Object> resindex(HttpServletRequest request, HttpServletResponse response, Model model) {
		Map<String ,Object> map=new HashMap<String ,Object>();
		int pageIndex =Integer.valueOf(request.getParameter("page")); //第几页的数据  
	    int pageSize = Integer.valueOf(request.getParameter("rows")); //每页多少条数据  
	    List<Resources> ress=resService.findResPageing(pageIndex,pageSize);
		//model.addAttribute("userList", userService.findAllUserList()); 
	    int total=resService.findAllResList().size();
	    map.put("total", total);
	    map.put("rows", ress);
		return map;
	}
	
	//模糊搜索 分页
	@ResponseBody
	@RequestMapping("/seachrestab")
	public Map<String ,Object> seachresindex(HttpServletRequest request, HttpServletResponse response, Model model) {
		Map<String ,Object> map=new HashMap<String ,Object>();
		int pageIndex =Integer.valueOf(request.getParameter("page")); //第几页的数据  
	    int pageSize = Integer.valueOf(request.getParameter("rows")); //每页多少条数据 
		String value=request.getParameter("txt");
		List<Resources> ress=resService.findResList(value, pageIndex, pageSize);
		//model.addAttribute("resList", resService.findResList(value));
		int total=resService.findResList(value).size();
		map.put("total", total);
	    map.put("rows", ress);
		return map;
	}
		

}
